package tech.tongyu.bob.demo.proxy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.tongyu.bob.demo.proxy.cglibproxy.proxy.TransactionProxy;
import tech.tongyu.bob.demo.proxy.cglibproxy.service.BookService;


@RestController
public class BookController {


    private BookService bookService = new BookService();

//    @Autowired
//    public BookController(BookService bookService) {
//        this.bookService = TransactionProxy.createProxy(bookService.getClass());
//    }


    @GetMapping("/cglibproxy/book")
    //@PutMapping 为了符合restful风格
    public ResponseEntity<String> add() {
        bookService = TransactionProxy.createProxy(bookService.getClass());
        // 调用代理类的 register
        bookService.addBook();
        return ResponseEntity.ok("添加书籍 success");
    }

}
